package com.anti.modular.sys.role.controller;

import com.anti.commom.annotation.DataScope;
import com.anti.commom.annotation.Permission;
import com.anti.commom.api.Result;
import com.anti.commom.enums.LogAnnotionOpTypeEnum;
import com.anti.jdbc.support.page.PageParam;
import com.anti.commom.annotation.BusinessLog;
import com.anti.modular.sys.role.param.SysRoleParam;
import com.anti.modular.sys.role.service.SysRoleService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Description TODO
 * @Author anTi
 * @Date 2021-3-10
 */
@RestController
@RequestMapping("sysRole")
public class SysRoleController {

    @Resource
    SysRoleService sysRoleService;

    /**
     * 添加系统角色
     */
    @Permission
    @PostMapping("add")
    @BusinessLog(title = "系统角色_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public Result add(@RequestBody @Validated(SysRoleParam.add.class) SysRoleParam sysRoleParam) {
        sysRoleService.add(sysRoleParam);
        return Result.success("新增成功！");
    }
    /**
     * 删除系统角色
     */
    @Permission
    @PostMapping("delete")
    @BusinessLog(title = "系统角色_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public Result delete(@RequestBody @Validated(SysRoleParam.delete.class) SysRoleParam sysRoleParam) {
        sysRoleService.delete(sysRoleParam);
        return Result.success("删除成功！");
    }

    /**
     * 编辑系统角色
     */
    @PostMapping("/edit")
    @BusinessLog(title = "系统角色_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public Result edit(@RequestBody @Validated(SysRoleParam.edit.class) SysRoleParam sysRoleParam) {
        sysRoleService.edit(sysRoleParam);
        return Result.success("修改成功！");
    }

    /**
     * 查询系统角色
     */
    @GetMapping("page")
    @BusinessLog(title = "系统角色_查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public Result page(PageParam pageParam, SysRoleParam sysRoleParam) {
        return Result.data(sysRoleService.page(pageParam,sysRoleParam));
    }
    /**
     * 拥有菜单
     */
    @GetMapping("ownMenu")
    @BusinessLog(title = "系统角色_拥有菜单", opType = LogAnnotionOpTypeEnum.DETAIL)
    public Result ownMenu(@Validated(SysRoleParam.detail.class) SysRoleParam sysRoleParam) {
      return  Result.data(sysRoleService.ownMenu(sysRoleParam));
    }

    /**
     * 授权菜单
     */
    @PostMapping("grantMenu")
    @BusinessLog(title = "系统角色_授权菜单", opType = LogAnnotionOpTypeEnum.GRANT)
    public Result grantMenu(@RequestBody @Validated(SysRoleParam.grantMenu.class) SysRoleParam sysRoleParam) {
        sysRoleService.saveGrantMenu(sysRoleParam);
        return Result.success("授权成功");
    }


    /**
     * 授权数据
     */
    @DataScope
    @PostMapping("grantData")
    @BusinessLog(title = "系统角色_授权数据", opType = LogAnnotionOpTypeEnum.GRANT)
    public Result grantData(@RequestBody @Validated(SysRoleParam.grantData.class) SysRoleParam sysRoleParam) {
        sysRoleService.saveGrantData(sysRoleParam);
        return  Result.success("数据授权成功");
    }
    /**
     * 拥有数据
     */
    @GetMapping("ownData")
    @BusinessLog(title = "系统角色_拥有数据", opType = LogAnnotionOpTypeEnum.DETAIL)
    public Result ownData(@Validated(SysRoleParam.detail.class) SysRoleParam sysRoleParam) {
        return  Result.data(sysRoleService.ownData(sysRoleParam));
    }
}
